//
//  Session.m
//  MobilCommunity
//
//  Created by easystudio on 7/7/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Session.h"
#import "DHCUtil.h"

@implementation Member

@synthesize user_id;
@synthesize user_pass;
@synthesize user_name;
@synthesize name_cn;
@synthesize role_id;
@synthesize role_name;
@synthesize posi_id;
@synthesize posi_name;
@synthesize permission;
@end


static Session* _session;

@implementation Session

@synthesize MsgCount1;
@synthesize MsgCount2;
@synthesize MsgCount3;
@synthesize MsgCount4;
@synthesize MsgCount5;
@synthesize MailAddress;
@synthesize CompanyCode;


+ (Session*) share
{
    if (_session) {
        return _session;
    }
    _session = [[Session alloc] init];
    
    return _session;
}


- (Session*) init
{
    self = [super init];
    
    _bLogined = NO;
    _sMember = [[Member alloc] init];
    MsgCount1 = 0;
    MsgCount2 = 0;
    MsgCount3 = 0;
    MsgCount4 = 0;
    MsgCount5 = 0;
    
    return self;
}

-(BOOL) isLogined
{
    return _bLogined;
}

-(void) setLoginFlag:(BOOL) flag
{
    _bLogined = flag;
}

-(BOOL) isChance
{
    return _isChance;
}
-(void) setChance:(BOOL) flag
{
    _isChance = flag;
}


- (NSString*) getMemberID
{
    return _sMember.user_id;
}
- (NSString*) getMemberPass
{
    return _sMember.user_pass;
}
- (NSString*) getMemberName
{
    return _sMember.user_name;
}
- (NSString*) getMemberNickName
{
    return _sMember.name_cn;
}
- (NSString*) getMemberRoleID
{
    return _sMember.role_id;
}
- (NSString*) getMemberRoleName
{
    return _sMember.role_name;
}
- (NSString*) getMemberPosiID
{
    return _sMember.posi_id;
}
- (NSString*) getMemberPosiName
{
    return _sMember.posi_name;
}

- (BOOL) getMemberPermission
{
    return _sMember.permission;
}

-(BOOL) getPermission
{
    return _sMember.permission;
}
-(void) setPermission:(BOOL) perm
{
    _sMember.permission = perm;
}

- (Member *) getMember
{
    return _sMember;
}

- (void) setMember:(NSMutableDictionary *)member
{
    _sMember.user_id = [member objectForKey:Key_SaveLogin_UserID];
    _sMember.user_pass = [member objectForKey:Key_SaveLogin_PassWord];
    _sMember.user_name = [member objectForKey:Key_SaveLogin_UserName];
    _sMember.name_cn = [member objectForKey:Key_SaveLogin_NickName];
    _sMember.role_id = [member objectForKey:Key_SaveLogin_RoleID];
    _sMember.posi_id = [member objectForKey:Key_SaveLogin_PosiID];
    _sMember.posi_name = [member objectForKey:Key_SaveLogin_PosiName];
}

-(void)printMember{    
    NSLog(@"Session==>isLogined=%d;user_id=%@;user_name=%@;name_cn=%@;role_id=%@;posi_id=%@;posi_name=%@,permission=%d,isChance=%d,msgCount1=%d,msgCount2=%d,msgCount3=%d,msgCount4=%d,msgCount5=%d,mail=%@,CompanyCode=%@",
          _bLogined,_sMember.user_id,_sMember.user_name,_sMember.name_cn,_sMember.role_id,_sMember.posi_id,_sMember.posi_name,_sMember.permission,
          _isChance,
          MsgCount1,MsgCount2,MsgCount3,MsgCount4,MsgCount5,
          MailAddress,
          CompanyCode);
}

- (void) logout
{
    _bLogined = NO;
}

- (void)dealloc {
    [_sMember release];
//    [_sPositions release];
    [super dealloc];
}
@end
